﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VirtualPress.Infrastructure.Entities.Repository;
using VirtualPress.Infrastructure.Entities.Enum;
using VirtualPress.Infrastructure.Entities.Cache;

namespace VirtualPress.Infrastructure.Entities.Entity
{
    public class Article : IAccessible<T_Article, Article>, ILogicEntity<T_Article, Article>
    {
        #region Fileds
        public int Id { get; set; }
        /// <summary>
        /// 稿件状态
        /// </summary>
        public ArticleStatus Status { get; set; }
        /// <summary>
        /// 稿件归属
        /// </summary>
        public ArticleType ArticleType { get; set; }
        /// <summary>
        /// 用户名
        /// </summary>
        public string UserName { get; set; }
        /// <summary>
        /// 所属期刊Id
        /// </summary>
        public int Peri_Id { get; set; }
        /// <summary>
        /// 所装订入期刊号
        /// </summary>
        public int PeriItem_Id { get; set; }
        /// <summary>
        /// 稿件编号
        /// </summary>
        public string Code { get; set; }
        /// <summary>
        /// 稿件类型
        /// </summary>
        public int Type { get; set; }
        /// <summary>
        /// 领域代码
        /// </summary>
        public int FiedCode { get; set; }
        /// <summary>
        /// 子领域代码
        /// </summary>
        public int SubFiedCode { get; set; }
        /// <summary>
        /// 中图分类号
        /// </summary>
        public string ZTFLH { get; set; }
        /// <summary>
        /// 文献标识码
        /// </summary>
        public string WM { get; set; }
        /// <summary>
        /// 所属会议Id
        /// </summary>
        public int Conference_Id { get; set; }
        /// <summary>
        /// 所属会议项Id
        /// </summary>
        public int ConferenceItem_Id { get; set; }
        /// <summary>
        /// 稿件标题
        /// </summary>
        public string Title { get; set; }
        /// <summary>
        /// 稿件标题_EN
        /// </summary>
        public string Title_EN { get; set; }
        /// <summary>
        /// 摘要
        /// </summary>
        public string Abstract { get; set; }
        /// <summary>
        /// 摘要_EN
        /// </summary>
        public string Abstract_EN { get; set; }
        /// <summary>
        /// 关键词
        /// </summary>
        public string KeyWords { get; set; }
        /// <summary>
        /// 关键词_EN
        /// </summary>
        public string KeyWords_EN { get; set; }
        public DateTime CreateTime { get; set; }
        public DateTime SubmitTime { get; set; }
        public int PageSize { get; set; }
        /// <summary>
        /// 支付总额
        /// </summary>
        public int TotalPay { get; set; }
        public string GJFW { get; set; }
        public bool IsDelete { get; set; }
        /// <summary>
        /// 专家推荐材料
        /// </summary>
        public string Recommendation { get; set; }
        public int DownloadNumber { get; set; }
        public int VisitNumber { get; set; }
        #endregion

        /// <summary>
        /// 所属期刊项代码
        /// </summary>
        public string Peri_Item_Code { get; set; }
        public string MeetingItem_Code { get; set; }
        public Periodical Journal { get; set; }
        public PeriodicalItem journalItem { get; set; }
        public List<ArticleAuthor> ArticleAuthor { get; set; }
        public List<Appendix> Appendix { get; set; }
        public Meeting Meeting { get; set; }
        public int ExamineTotle { get; set; }
        public int ExamineComplete { get; set; }
        /// <summary>
        /// 待支付费用
        /// </summary>
        public int WaitPay { get; set; }
        protected override void Covariant(T_Article model)
        {
            if (model != null)
            {
                this.UserName = model.UserName;
                this.Abstract = model.Abstract;
                this.Abstract_EN = model.Abstract_EN;
                this.ArticleType = (Enum.ArticleType)model.ArticleType;
                this.Code = model.Code;
                this.CreateTime = model.CreateTime;
                this.FiedCode = model.FiedCode;
                this.Id = model.Id;
                this.KeyWords = model.KeyWords;
                this.KeyWords_EN = model.KeyWords_EN;
                this.Peri_Id = model.Peri_Id;
                this.SubmitTime = model.SubmitTime;
                this.Title = model.Title;
                this.Title_EN = model.Title_EN;
                this.Type = model.Type;
                this.WM = model.WM;
                this.Conference_Id = model.Conference_Id;
                this.ConferenceItem_Id = model.ConferenceItem_Id;
                this.ZTFLH = model.ZTFLH;
                this.PeriItem_Id = model.PeriItem_Id;
                this.PageSize = model.PageSize;
                this.SubFiedCode = model.SubFiedCode;
                this.Status = (ArticleStatus)model.Status;
                this.TotalPay = model.TotalPay;
                this.IsDelete = model.IsDelete;
                this.GJFW = model.GJFW;
                this.Recommendation = model.Recommendation;
                this.DownloadNumber = model.DownloadNumber;
                this.VisitNumber = model.VisitNumber;
            }
        }

        protected override T_Article Inverter(Article model)
        {
            if (model != null)
            {
                return new T_Article()
                {
                    Abstract = model.Abstract,
                    Abstract_EN = model.Abstract_EN,
                    ArticleType=(int)model.ArticleType,
                    Code = model.Code,
                    CreateTime = model.CreateTime,
                    FiedCode = model.FiedCode,
                    Id = model.Id,
                    KeyWords = model.KeyWords,
                    KeyWords_EN = model.KeyWords_EN,
                    Peri_Id = model.Peri_Id,
                    SubmitTime = model.SubmitTime,
                    Title = model.Title,
                    Title_EN = model.Title_EN,
                    WM = model.WM,
                    Conference_Id = model.Conference_Id,
                    ZTFLH = model.ZTFLH,
                    UserName = model.UserName,
                    PeriItem_Id = model.PeriItem_Id,
                    ConferenceItem_Id=model.ConferenceItem_Id,
                    PageSize=model.PageSize,
                    SubFiedCode=model.SubFiedCode,
                    Type=model.Type,
                    Status=(int)model.Status,
                    TotalPay=model.TotalPay,
                    IsDelete =model.IsDelete,
                    GJFW=model.GJFW,
                    Recommendation=model.Recommendation,
                    DownloadNumber=model.DownloadNumber,
                    VisitNumber=model.VisitNumber
                };
            }
            return null;
        }

        public override Article Find(string key)
        {
            return new ArticleCache().GetItem(key);
        }
        public override Article PostDelete()
        {
            new ArticleCache().RefreshItem(Id.ToString());
            return base.PostDelete();
        }
        public override Article PostModify()
        {
            new ArticleCache().RefreshItem(Id.ToString());
            return base.PostModify();
        }

        public Article Set(T_Article dbModel)
        {
            Covariant(dbModel);
            return this;
        }
        public Article LoadJournal(Periodical journal)
        {
            this.Journal = journal;
            return this;
        }
        public Article LoadMeeting(Meeting meeting)
        {
            this.Meeting = meeting;
            return this;
        }
        public Article LoadArticleAuthor(List<ArticleAuthor> authors)
        {
            this.ArticleAuthor = authors;
            return this;
        }
        public Article SetJournalItemCode(string code)
        {
            this.Peri_Item_Code = code;
            return this;
        }
        public Article SetMeetingItemCode(string code)
        {
            this.MeetingItem_Code = code;
            return this;
        }
        public Article LoadAttachment(List<Appendix> attachment)
        {
            this.Appendix = attachment;
            return this;
        }
        public Article LoadJournalItem(PeriodicalItem journalItem)
        {
            this.journalItem = journalItem;
            return this;
        }
    }
}
